﻿using BUGCOME.Infrastructure;
using BUGCOME.Infrastructure.Model;
using BUGCOME.Service.Auth;
using BUGCOME.Service.Auth.IServices;
using BUGCOME.ServiceCore.Services.IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace BUGCOME.Auth.Api.Controllers
{
    /// <summary>
    /// 路由管理API控制器
    /// </summary>
    [Route("authapi/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "router")]
    public class RouterController : BaseController
    {
        /// <summary>
        /// 菜单服务
        /// </summary>
        private readonly IMenuService menuService;

        /// <summary>
        /// 注入菜单服务初始化
        /// </summary>
        /// <param name="menuService">菜单服务</param>
        public RouterController(IMenuService menuService)
        {
            this.menuService = menuService;
        }

        /// <summary>
        /// 获取路由信息（HttpGet请求）
        /// </summary>
        /// <returns>路由信息的异步响应结果</returns>
        [HttpGet]
        public async Task<IActionResult> GetRouterInfo()
        {
            var json = JsonConvert.DeserializeObject("[]");

            long uid = HttpContext.GetUId();
            var menus = await menuService.SelectMenuTreeByUserIdAsync(uid);
            return ToResponse(ApiResult.Success(menuService.BuildMenus(menus)));
        }
    }
}